package org.six11.olive3.client;

import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;

import org.six11.olive3.net.MessageNames;
import org.six11.olive3.net.OliveNetworkTransmitter;
import org.six11.olive3.net.Message.Statement;
import org.six11.util2.pen.MouseThing;
import org.six11.util2.pen.Pt;
import org.six11.util2.Debug;
import org.six11.util2.pen.Sequence;

import sun.net.ProgressSource.State;
import static org.six11.olive3.net.Message.*;

/**
 * 
 * 
 * @author Gabe Johnson <johnsogg@cmu.edu>
 * 
 */
public class OliveMouseThing extends MouseThing {

  private OliveState state;
  private OliveNetworkTransmitter xmit;

  OliveMouseThing(OliveState state, OliveNetworkTransmitter xmit) {
    this.state = state;
    this.xmit = xmit;
  }

  public void mousePressed(MouseEvent ev) {
    state.addLocalSequenceBegin(new Pt(ev));
    xmit.addToMessage(getPenSignature(), getPtString(ev));
  }

  public void mouseDragged(MouseEvent ev) {
    state.addLocalSequenceProgress(new Pt(ev));
    xmit.addToMessage(getPenSignature(), getPtString(ev));
  }

  public void mouseReleased(MouseEvent ev) {
    state.addLocalSequenceEnd(new Pt(ev));
    xmit.addToMessage(getPenSignature(), "up t=" + ev.getWhen());
  }

  @SuppressWarnings("unused")
  private void bug(final String what) {
    Debug.out("OliveMouseThing", what);
  }

  public String getPenSignature() {
     String ret = MessageNames.MSG_PEN + " (" + MessageNames.PARAM_USER_ID + "=\"" + state.getUserID() + "\")";
     return ret;
  }
  
  public static String getPtString(MouseEvent ev) {
    return "pt " + ev.getX() + " " + ev.getY() + " t=" + ev.getWhen();
  }
}
